package org.xs.web.http.validate;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class ValidateExecutor {
	 
	private static List<ValidateMap> validates = new ArrayList<ValidateMap>();
	private static List<FieldErrorMsg> success = new ArrayList<FieldErrorMsg>(0);
	
	
	public static void addValidateMap(ValidateMap map){
		validates.add(map);
	}
 
	public static List<FieldErrorMsg> validate(String ctr,String action,Map<String,Object> form){
		ValidateEntry vs=null;
		ValidateEntry tmep=null;
		for(ValidateMap entry : validates){
			tmep = entry.getValidates(ctr==null?"":ctr,action);
			if(tmep != null){
				vs = tmep;
				break;
			}
		}
		if(vs != null){
			return vs.validate(form); 
		}
		return success;
	}
	
}

